cmake_minimum_required(VERSION 3.15)

project(CAD)

include(CheckIncludeFileCXX)

# 判断当前目录是否为 cmake的根目录,如果不是,则是被其他项目引用的,不需要编译测试,工具模块
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
    set(SU_AS_PROJECT TRUE)
    set(SU_AS_LIB FALSE)
else ()
    set(SU_AS_PROJECT FALSE)
    set(SU_AS_LIB TRUE)
endif ()

if (SU_AS_PROJECT)

    # 设置默认程序根目录,程序中所有路径均参照此路径,方便调试和发布
    if (IS_DEBUG)
        add_definitions("-DDEFAULT_ROOT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
    else ()
        # add_definitions("-DDEFAULT_ROOT_DIR=\"\"")
        add_definitions("-DDEFAULT_ROOT_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"")
    endif ()

    add_definitions("-DDEFAULT_DATA_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}/data\"")
    set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake;${CMAKE_MODULE_PATH}")

endif ()


# 头文件
include(all_in_one)
include(env_check)

# 添加core目录下的头文件到项目
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/core)

# 添加 openccasec 头文件
find_package(OpenCASCADE CONFIG REQUIRED)
include_directories(${OpenCASCADE_INCLUDE_DIR})

# 添加库文件
link_directories(${OpenCASCADE_LIBRARY_DIR})
message(STATUS "OpenCASCADE_LIBRARY_DIR: ${OpenCASCADE_LIBRARY_DIR}")

set(QT_VERSION_MAJOR 5 CACHE STRING "Force Qt5" FORCE)
set(QT_PREFERRED_VERSION 5)
set(QT_NO_GLOBAL_FIND_PACKAGE_Qt6 TRUE)

set(Qt5_DIR "D:/software/ide/qt_5_15_2/5.15.2/msvc2019_64/lib/cmake/Qt5")
SET(QT_SDK_DIR "D:/software/ide/qt_5_15_2/5.15.2/msvc2019_64" CACHE PATH "QT SDK DIR" FORCE)


SET(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/Install CACHE PATH "Installation path" FORCE)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

message("在CMAKE中配置 QT_SDK_DIR 选项指定QT路径; 当前路径: ${QT_SDK_DIR}")
message(STATUS "Setting Qt5_DIR to: ${Qt5_DIR}")
message("QT_VERSION_MAJOR: ${QT_VERSION_MAJOR}")


# 添加目录
add_subdirectory(core)  # core代码
add_subdirectory(src)   # 主函数
add_subdirectory(test)   # 测试

